library(plotrix)

df <- readRDS("df.rds")

################
### FIGURE 1 ###
################

dta <- cbind(df[df$q.p=="q", c("id", "numc", "numo", "numm")], 
    df[df$q.p=="p", c("id", "numc", "numo", "numm")])

names(dta) <- c("id_q", "conditions_questionnaire", 
    "outcomes_questionnaire", "other_questionnaire",
    "id_p", "conditions_paper", "outcomes_paper", "other_paper")
  
pdf(file = "figure_1.pdf", width=10, height=5.5)
par(bg="white", mfrow=c(1,2), mar=c(6, 5, 5,1),cex.axis=1.3)

with(dta, sizeplot(conditions_questionnaire, conditions_paper,
    xlim=c(0,max(c(conditions_questionnaire, conditions_paper))),
    ylim=c(0,max(c(conditions_questionnaire, conditions_paper))),
    xlab="", pch=16, ylab=""))
abline(coef=c(0,1))
title(xlab="Questionnaire", cex.lab=1.3,  line=3)
title(ylab="Article", cex.lab=1.3, line=3)
title(main="A) Number of experimental conditions", cex.main=1.3, line=2)

with(dta, sizeplot(outcomes_questionnaire, outcomes_paper,
    xlim=c(0,max(c(outcomes_questionnaire, outcomes_paper))+1),
    ylim=c(0,max(c(outcomes_questionnaire,outcomes_paper))+1),
    xlab="", pch=16, ylab=""))
abline(coef=c(0,1))
title(xlab="Questionnaire", cex.lab=1.3,  line=3)
title(ylab="Article", cex.lab=1.3, line=3)
title(main="B) Number of outcome variables", cex.main=1.3, line=2)

dev.off()

#################
### FIGURE O1 ###
#################

pdf(file = "figure_o1.pdf", width=4.5, height=5)
par(bg="white", mfrow=c(1,1), mar=c(6, 5, 5,1),cex.axis=1.3)
with(dta, sizeplot(other_questionnaire, other_paper, xlab="", 
    pch=16, ylab="", xlim=c(0,20), ylim=c(0,20)))
abline(coef=c(0,1))
title(xlab="Questionnaire", cex.lab=1.3,  line=3)
title(ylab="Article", cex.lab=1.3, line=3)
title(main="Number of \"other variables\"", cex.main=1.3, line=2)
dev.off()

########################
### TABLE 2/TABLE O1 ###
########################

set.seed(83738180)

boot <- function(x){
    b <- replicate(100000, sample(x, length(x), replace=T))
    means <- colMeans(b)
    m <- means[order(means)]
    nulls <- as.numeric(m==0)
    return(c(mean(x), sd(m), m[0.025*100000], m[0.975*100000]))
}

dta$conditions_difference <- dta$conditions_questionnaire - dta$conditions_paper
dta$outcomes_difference <- dta$outcomes_questionnaire - dta$outcomes_paper
dta$other_difference <- dta$other_questionnaire - dta$other_paper

attach(dta)

vars <- list(
    conditions_questionnaire, conditions_paper, conditions_difference,
    outcomes_questionnaire, outcomes_paper, outcomes_difference,
    other_questionnaire, other_paper, other_difference)
      
t <- round(sapply(vars, boot), 1)
t
      